<template>
  <div class="app-container">
    <Ht-search-form
      v-show="showSearch"
      :dictMap="dictMap"
      :queryParams="queryParams"
      :outputQueryParams="queryParams"
      :formOptions="formOptions"
      :advOptions="[]"
      :beforeSearchCallback="false"
      @beforeSearchCallback="beforeSearchCallback"
      :clearCallBack="clearCallBack"
      :defaultEventKey="defaultEventKey"
      :labelWidth="75"
    >
      <template slot="endSlotOption">
        <amount-range-search label="金额区间" ref="amountRangeSearch"></amount-range-search>
      </template>
    </Ht-search-form>

    <ht-table
      ref="dataTable"
      :multi-select="false"
      :showSerialNumber="false"
      :dictMap="dictMap"
      :queryParams="queryParams"
      :tableBindColumns="tableBindColumns"
      :opButtonList="opButtonList"
      :reqConfig="regConfig"
      :randomRowKey="true"
      :defaultEventKey="defaultEventKey"
    >
      <template v-slot:operate>
        <el-table-column label="操作" align="left" width="50" fixed="right">
          <template slot-scope="scope">
            <ht-button-group
              :buttonList="[
                {
                  label: '明细',
                  doFunc: () => {
                    handleAction('detail', scope.row);
                  },
                },
              ]"
            />
          </template>
        </el-table-column>
      </template>
    </ht-table>

    <!-- 明细弹出框 -->
    <beps-debit-nostro-hd-wk-detail127
      ref="bepsDebitNostroHdWkDetail127Dialog"
      :dictMap="dictMap"
      :detailForm.sync="detailForm"
      @editComplete="editComplete"
    ></beps-debit-nostro-hd-wk-detail127>

    <beps-debit-nostro-hd-wk-detail133
      ref="bepsDebitNostroHdWkDetail133Dialog"
      :dictMap="dictMap"
      :detailForm.sync="detailForm"
      @editComplete="editComplete"
    ></beps-debit-nostro-hd-wk-detail133>
  </div>
</template>

<script>
import { listPageMixin } from "@/libs/listPageMixin";
import AmountRangeSearch from "@/views/components/AmountSearchInput";
import { bepsDebitNostroHdWkDetail, bepsDebitNostroHdWkQuery } from "@/api/cnaps/beps/baseHandWork/bepsDebitNostroHdWk";
import { amountThousandsFormatter } from "@/utils/table_col_formatter";
import bepsDebitNostroHdWkDetail127 from "@/views/cnaps/beps/baseHandWork/components/BepsDebitNostroHdWkDetail127";
import bepsDebitNostroHdWkDetail133 from "@/views/cnaps/beps/baseHandWork/components/BepsDebitNostroHdWkDetail133";

export default {
  name: "BepsDebitNostroHdWk",
  mixins: [listPageMixin],
  components: { AmountRangeSearch, bepsDebitNostroHdWkDetail127, bepsDebitNostroHdWkDetail133 },
  data() {
    return {
      // 查询参数
      queryParams: {
        id: undefined,
        cpgdate1: undefined,
        cpgdate2: undefined,
        workdate1: undefined,
        workdate2: undefined,
        amount1: undefined,
        amount2: undefined,
      },

      defaultEventKey:"defaultEventKey",

      detailForm: {
        data: {},
        data2: {},
      },
      loading: false,
      // 搜索
      formOptions: [],
      //
      searchFormDictList: [
        "PKG_STATUS",
        "NSTP_TYPE",
        "CBFLAG",
        "BIZRT_STATUS",
        "RegionId",
        "BUDGETLEVELCODE",
        "INDICATOR_CODE",
        "BUDGETTYPECODE",
        "DEPT_CODE",
        "REJECTCODE_BILL",
        "REJECTCODE_NOTES",
        "REJECTCODE_030401",
      ],
      // 列信息
      regConfig: bepsDebitNostroHdWkQuery,
      tableBindColumns: [
        { prop: "bepsId", label: "交易流水号", width: 180 },
        { prop: "pkgId", label: "报文标识号", width: 180 },
        { prop: "cpgdate", label: "CPG日期", type: "date", width: 120 },
        { prop: "workdate", label: "工作日期", type: "date", width: 120 },
        {
          prop: "msgtype",
          label: "报文类型",
          formatter(row, text, index) {
            return (
              (row["msgtype"] === null || row["msgtype"] === undefined ? "" : row["msgtype"]) +
              "-" +
              (row["msgtypeDesc"] === null || row["msgtypeDesc"] === undefined ? "" : row["msgtypeDesc"])
            );
          },
          width: 240,
        },
        {
          prop: "bizTypeCode",
          label: "业务类型",
          formatter(row, text, index) {
            return (
              (row["bizTypeCode"] === null || row["bizTypeCode"] === undefined ? "" : row["bizTypeCode"]) +
              "-" +
              (row["bizTypeCodeDesc"] === null || row["bizTypeCodeDesc"] === undefined ? "" : row["bizTypeCodeDesc"])
            );
          },
          width: 180,
        },
        { prop: "status", label: "通讯状态", dictCode: "PKG_STATUS", width: 120 },
        { prop: "rcvTime", label: "报文接收时间", type: "date", width: 180 },
        { prop: "amount", label: "交易金额", type: "price"},
      ],
    };
  },
  mounted() {
    this.$refs.amountRangeSearch.$on('getAmountRange',this.beforeSearchCallback);
    const formOptions = [
      // 普通搜索
      {
        type: "dates",
        nameObj: {
          startTimeName: "cpgdate1",
          endTimeName: "cpgdate2",
        },
        defaultAttr: {
          size: "small",
          label: "CPG日期",
          placeholder: ["请输入CPG日期开始", "请输入CPG日期结束"],
          format: "yyyy-MM-dd",
          valueFormat: "yyyyMMdd",
        },
      },
      {
        type: "dates",
        nameObj: {
          startTimeName: "workdate1",
          endTimeName: "workdate2",
        },
        defaultAttr: {
          size: "small",
          label: "工作日期",
          placeholder: ["请输入工作日期开始", "请输入工作日期结束"],
          format: "yyyy-MM-dd",
          valueFormat: "yyyyMMdd",
        },
      },
      {
        type: "input",
        prop: "id",
        defaultAttr: {
          size: "small",
          label: "交易流水号",
          placeholder: "请输入交易流水号",
        },
      },
    ];
    this.formOptions = formOptions;
  },
  methods: {
    /***
     * 按钮操作汇总
     */
    /***
     * 按钮操作汇总
     */
    handleAction(type, row = {}) {
      switch (type) {
        case "detail":
          this.handleDetail(row);
          break;
      }
    },

    // 关闭按钮
    cancel() {
      this.open = false;
    },

    beforeSearchCallback() {
      // 搜索按钮之前先执行
      this.queryParams.amount1 = this.$refs.amountRangeSearch.getAmount1();
      this.queryParams.amount2 = this.$refs.amountRangeSearch.getAmount2();
    },
    clearCallBack() {
      let that = this;
      return new Promise(function (resolve, reject) {
        that.$refs.amountRangeSearch.clearAmount();
        that.queryParams.amount1 = "";
        that.queryParams.amount2 = "";
        resolve();
      });
    },

    /** 详情按钮操作 */
    handleDetail(row) {
      bepsDebitNostroHdWkDetail(row).then((response) => {
        if (row.msgtype === "beps.127.001.01" || row.msgtype === "beps.127.001.02") {
          this.detailForm = response.result;
          this.detailForm.data.drctCny = "CNY";
          this.$refs.bepsDebitNostroHdWkDetail127Dialog.show();
        } else if ("beps.133.001.01" === row.msgtype) {
          this.detailForm = response.result.data;
          this.$refs.bepsDebitNostroHdWkDetail133Dialog.show();
        }
      });
    },
  },
};
</script>
